/**
 * Created by asus on 2018/4/7.
 * 购物车模块业务请求
 */

var _mm = require("util/mm.js");

var _cart = {
    //1.获取购物车数量
    getCartCount : function(resolve, reject){
        _mm.request({
            url     : _mm.getServerUrl('/cart/get_cart_product_count.do'),
            success : resolve,
            method : "get",
            error   : reject
        });
    },
    //2.添加到购物车
    addToCart :function(productInfo,resolve, reject){
        _mm.request({
            url     : _mm.getServerUrl('/cart/add_list.do'),
            data : productInfo,
            method : "post",
            success : resolve,
            error   : reject
        });
    },
    //3.获取当前用户的购物车信息
    getCartList : function(resolve, reject){
        _mm.request({
            url     : _mm.getServerUrl('/cart/cart_list.do'),
            success : resolve,
            method : "get",
            error   : reject
        });
    },
    //4.单选购物车的商品
    selectProduct : function(productId,resolve, reject){
        _mm.request({
            url     : _mm.getServerUrl('/cart/select.do'),
            data : {
                productId : productId
            },
            method : "post",
            success : resolve,
            error   : reject
        });
    },
    //5.单反选购物车的商品
    unSelectProduct : function(productId,resolve, reject){
        _mm.request({
            url     : _mm.getServerUrl('/cart/un_select.do'),
            data : {
                productId : productId
            },
            method : "post",
            success : resolve,
            error   : reject
        });
    },
    //6.全选所有的商品
    selectAllProduct : function (resolve, reject) {
        _mm.request({
            url     : _mm.getServerUrl('/cart/select_all.do'),
            method : "post",
            success : resolve,
            error   : reject
        });
    },
    //7.全反选所有的商品
    unSelectAllProduct : function (resolve, reject) {
        _mm.request({
            url     : _mm.getServerUrl('/cart/un_select_all.do'),
            method : "post",
            success : resolve,
            error   : reject
        });
    },
    //8.更新购物车的数量
    updateProduct : function (productInfo,resolve, reject) {
        _mm.request({
            url     : _mm.getServerUrl('/cart/update.do'),
            data : productInfo,
            method : "post",
            success : resolve,
            error   : reject
        });
    },
    //9.删除的选中的商品，可以是一件，也可以是多件
    deleteProducts : function(productIds,resolve, reject){
        _mm.request({
            url     : _mm.getServerUrl('/cart/delete.do'),
            data : {
                productIds :productIds
            },
            method : "post",
            success : resolve,
            error   : reject
        });
    }
}

module.exports = _cart;